//
//  LLHttpTool.m
//  Weibo
//
//  Created by 李灵斌 on 15-2-6.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "LLHttpTool.h"

@implementation LLHttpTool


+ (void)GET:(NSString *)UrlStr parameters:(id)parameters success:(void(^)(id response))success failure:(void(^)(NSError *error))failure{
    
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:UrlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            
            failure(error);
        }
    }];
}

+ (void)POST:(NSString *)UrlStr parameters:(id)parameters success:(void(^)(id response))success failure:(void(^)(NSError *error))failure{
    
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr POST:UrlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            
            failure(error);
        }
    }];
}

+ (void)POST:(NSString *)UrlStr parameters:(id)parameters bodyBlock:(void(^)(id<AFMultipartFormData> formData))bodyBlock success:(void(^)(id response))success failure:(void(^)(NSError *error))failure{
    
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];

    [mgr POST:UrlStr parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        if (bodyBlock) {
            
            bodyBlock(formData);
        }
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            
            failure(error);
        }
    }];
}
@end
